package cn.dxh.stagefinal.service.impl;

import cn.dxh.stagefinal.bean.Provider;
import cn.dxh.stagefinal.dao.ProviderDao;
import cn.dxh.stagefinal.service.ProviderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * IntelliJ IDEA -> stagefinal
 * 2019/12/11 15:03
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
@Service
public class
ProviderServiceImpl implements ProviderService {
    @Autowired
    private ProviderDao providerDao;
    @Override
    public PageInfo<Provider> findProviders(Integer pageIndex, Integer pageSize, String pName, String pLinkMan) {
        PageHelper.startPage(pageIndex,pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("pName",pName);
        map.put("pLinkMan",pLinkMan);
        List<Provider> providers = providerDao.findProviders(map);
        PageInfo<Provider> providerPage = new PageInfo<>(providers);
        return  providerPage;

    }
@Transactional
    @Override
    public int insertProvider(Provider provider) {
        provider.setpState(1);
        return  providerDao.insertProvider(provider);
    }

    @Override
    public Provider findProviderByPid(Integer pId) {
        return providerDao.findProviderByPid(pId);
    }

    @Override
    public int updateProvider(Provider provider) {
        return providerDao.updateProvider(provider);
    }

    @Override
    public int deleteProvider(Integer pId, Integer pState) {
        Map<String, Object> map = new HashMap<>();
        map.put("pId",pId);
        map.put("pState",pState);
        return providerDao.deleteProvider(map);
    }

    @Transactional
    @Override
    public int deleteProviderByPids(int[] pIds) {
        return providerDao.deleteProviderByPids(pIds);
    }

    @Override
    public List<Provider> findProvidersByPid(int[] pIds) {
        return providerDao.findProvidersByPid(pIds);
    }
}
